package com.ruoyi.wechat;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.member.service.IMemberService;
import com.ruoyi.memberSer.domain.MemberSer;
import com.ruoyi.memberSer.service.IMemberSerService;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.wechat.domain.menu.ButtonBase;
import com.ruoyi.wechat.domain.menu.ButtonClick;
import com.ruoyi.wechat.domain.menu.ButtonList;
import com.ruoyi.wechat.domain.menu.ButtonMini;
import com.ruoyi.wechat.service.ButtonService;
import com.ruoyi.wechat.service.WeChatUserService;
import com.ruoyi.wechat.util.CommonUtil;
import com.ruoyi.wechat.util.MessageUtil;
import com.ruoyi.wechat.util.RequestUtil;
import com.ruoyi.wechat.util.SignUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 对外接口Controller
 *
 * @author jiuyou
 * @date 2021-03-02
 */
@RestController
@RequestMapping("/weChat/menu")
public class WeChatMenuController {

    @Autowired
    private ISysConfigService sysConfigService;
    @Autowired
    private ButtonService buttonService;
    @GetMapping (value = "cteateMenu")
    public AjaxResult cteateMenu(HttpServletRequest request, HttpServletResponse response, String APPKEY) {

        if(StringUtils.isEmpty(APPKEY)){
            return AjaxResult.error("参数错误");
        }
        String domain=sysConfigService.selectConfigByKey("domain");
        String url=domain+"/mp/qrcode.jpg";
        ButtonList obj=new ButtonList();
        List<ButtonBase> buttonList= new ArrayList<ButtonBase>();
        //第一个大菜单
        ButtonMini oneBtn=new ButtonMini();
        oneBtn.setName("美业团购");
        oneBtn.setUrl(url);
        oneBtn.setAppid(sysConfigService.selectConfigByKey("app_id"));
        oneBtn.setPagepath("pages/home/home");
        //第er个大菜单
        ButtonMini twoBtn=new ButtonMini();
        twoBtn.setName("我的账户");
        twoBtn.setUrl(url);
        twoBtn.setAppid(sysConfigService.selectConfigByKey("app_id"));
        twoBtn.setPagepath("pages/UCenter/index/index");

        ButtonMini threeBtn=new ButtonMini();
        threeBtn.setName("我是商家");
        threeBtn.setUrl(url);
        threeBtn.setAppid(sysConfigService.selectConfigByKey("app_id_store"));
        threeBtn.setPagepath("pages/middlePage/middlePage");
        buttonList.add(oneBtn);
        buttonList.add(twoBtn);
        buttonList.add(threeBtn);
        obj.setButton(buttonList);

       return AjaxResult.success(buttonService.createMenu(obj, APPKEY));
    }

}
